<?php
class clsArquivo extends clsAbertura {
	private $IDFIL, $TITULO, $FILENAME, $PATH, $FILESIZE, $CONTEUDO, $ISDEFAULT, $EXPSITE;
	private $EXPLV, $IDRC;
	/**
	 *
	 * @return the $IDFIL
	 */
	public function getIDFIL() {
		return $this->IDFIL;
	}
	
	/**
	 *
	 * @return the $TITULO
	 */
	public function getTITULO() {
		return $this->TITULO;
	}
	
	/**
	 *
	 * @return the $FILENAME
	 */
	public function getFILENAME() {
		return $this->FILENAME;
	}
	
	/**
	 *
	 * @return the $PATH
	 */
	public function getPATH() {
		return $this->PATH;
	}
	
	/**
	 *
	 * @return the $FILESIZE
	 */
	public function getFILESIZE() {
		return $this->FILESIZE;
	}
	
	/**
	 *
	 * @return the $CONTEUDO
	 */
	public function getCONTEUDO() {
		if ($this->CONTEUDO != '') {
			$nome = date ( 'YdmHis' ) . '-' . rand ( 000000000, 999999999 );
			$imagem = new clsUpload ( $this->CONTEUDO, $nome, '../../' . $this->getPATH () );
			
			$banner = 0;
			$rs = connectorFactory::query ( 'SELECT * FROM lojas WHERE idloja = ' . $_SESSION ['USUARIO'] ['LOJA'] );
			$rs = $rs [0];
			if ($banner == 1) {
				$tamanho = $rs ['TAMBAN'];
				$padrao = '980x328';
			} else {
				$tamanho = $rs ['TAMAMP'];
				$padrao = '900x600';
			}
			
			if ($tamanho == '')
				$tamanho = $padrao;
			
			$tamanho = explode ( 'x', $tamanho );
			$largura = $tamanho [0];
			$altura = $tamanho [1];
			
			$nome = $imagem->redimencionar ( $largura, $altura );
			$this->CONTEUDO = $nome;
		}
		return $this->CONTEUDO;
	}
	
	/**
	 *
	 * @return the $ISDEFAULT
	 */
	public function getISDEFAULT() {
		return $this->ISDEFAULT;
	}
	
	/**
	 *
	 * @return the $EXPSITE
	 */
	public function getEXPSITE() {
		return $this->EXPSITE;
	}
	
	/**
	 *
	 * @return the $EXPLV
	 */
	public function getEXPLV() {
		return $this->EXPLV;
	}
	
	/**
	 *
	 * @return the $IDRC
	 */
	public function getIDRC() {
		return $this->IDRC;
	}
	
	/**
	 *
	 * @param field_type $IDFIL        	
	 */
	public function setIDFIL($IDFIL) {
		if (! $IDFIL)
			$IDFIL = $this->dao->ultimoRegistro ( 'files', 'IDFIL', "" );
		$this->IDFIL = $IDFIL;
	}
	
	/**
	 *
	 * @param field_type $TITULO        	
	 */
	public function setTITULO($TITULO) {
		$this->TITULO = $TITULO;
	}
	
	/**
	 *
	 * @param field_type $FILENAME        	
	 */
	public function setFILENAME($FILENAME) {
		$this->FILENAME = $FILENAME;
	}
	
	/**
	 *
	 * @param field_type $PATH        	
	 */
	public function setPATH($PATH) {
		$this->PATH = $PATH;
	}
	
	/**
	 *
	 * @param field_type $FILESIZE        	
	 */
	public function setFILESIZE($FILESIZE) {
		$this->FILESIZE = $FILESIZE;
	}
	
	/**
	 *
	 * @param field_type $CONTEUDO        	
	 */
	public function setCONTEUDO($CONTEUDO) {
		$this->CONTEUDO = $CONTEUDO;
	}
	
	/**
	 *
	 * @param field_type $ISDEFAULT        	
	 */
	public function setISDEFAULT($ISDEFAULT) {
		$this->ISDEFAULT = $ISDEFAULT;
	}
	
	/**
	 *
	 * @param field_type $EXPSITE        	
	 */
	public function setEXPSITE($EXPSITE) {
		$this->EXPSITE = $EXPSITE;
	}
	
	/**
	 *
	 * @param field_type $EXPLV        	
	 */
	public function setEXPLV($EXPLV) {
		$this->EXPLV = $EXPLV;
	}
	
	/**
	 *
	 * @param field_type $IDRC        	
	 */
	public function setIDRC($IDRC) {
		$this->IDRC = $IDRC;
	}
	public function postar() {
		$a ['IDFIL'] = $this->getIDFIL ();
		$w = $a;
		$a ['CONTEUDO'] = $this->getCONTEUDO ();
		$a ['EXPLV'] = $this->getEXPLV ();
		$a ['EXPSITE'] = $this->getEXPSITE ();
		$a ['FILENAME'] = $this->getFILENAME ();
		$a ['FILESIZE'] = $this->getFILESIZE ();
		$a ['IDRC'] = $this->getIDRC ();
		$a ['ISDEFAULT'] = $this->getISDEFAULT ();
		$a ['PATH'] = $this->getPATH ();
		$a ['TITULO'] = $this->getTITULO ();
		
		$s = $this->dao->completo ( 'files', $a, $w, true );
		
		return $this->getIDFIL ();
	}
	public function deletar($TABELA, $CAMPOS, $IDFIL) {
		$PASTA = $this->dao->registro ( 'files', 'path', array (
				'idfil' => $IDFIL 
		) );
		$ARQUI = $this->dao->registro ( 'files', 'conteudo', array (
				'idfil' => $IDFIL 
		) );
		
		$x = $_SERVER ['DOCUMENT_ROOT'] . str_replace ( 'administrator/', '', PASTA ) . $PASTA . $ARQUI;
		unlink ( $x );
		$CAMPOS ['IDFIL'] = $IDFIL;
		$this->dao->deletar ( $TABELA, $CAMPOS );
		
		$a ['IDFIL'] = $IDFIL;
		return $this->dao->deletar ( 'files', $a );
	}
}
?>